package com.alm.token.ui.viewpagefragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alm.token.ConStant;
import com.alm.token.MyApp;
import com.alm.token.R;
import com.alm.token.base.BaseViewPageFragment;
import com.alm.token.ui.activity.ActivityListActivity;
import com.alm.token.ui.activity.BillActivity;
import com.alm.token.ui.activity.BlockWalletLoginActivity;
import com.alm.token.ui.activity.CandyActivity;
import com.alm.token.ui.activity.MainActivity;
import com.alm.token.ui.activity.MessageActivity;
import com.alm.token.ui.activity.MessageDetailActivity;
import com.alm.token.ui.activity.SetLanguageActivity;
import com.alm.token.ui.activity.SuperColorEggActivity;
import com.alm.token.ui.activity.TransferQrCodeActivity_new;
import com.alm.token.ui.activity.TransformActivity;
import com.alm.token.ui.activity.TurnOutBiTBActivity;
import com.alm.token.ui.activity.TurnOutBiTB_ShoukuanActivity;
import com.alm.token.ui.data.BaseDialogBean;
import com.alm.token.ui.data.bean.ChannelTypeData;
import com.alm.token.ui.data.bean.CoinDetailData;
import com.alm.token.ui.data.bean.DrawIndexData;
import com.alm.token.ui.data.bean.UserPayAdressData;
import com.alm.token.ui.data.bean.UserWalletData;
import com.alm.token.ui.fragmentDialog.CandyDialogFragment;
import com.alm.token.ui.fragmentDialog.CreatNodeDialogFragment;
import com.alm.token.ui.persenter.MyPreenter;
import com.alm.token.ui.view.UserWalletView;
import com.alm.token.utils.CommonUtil;
import com.alm.token.utils.EmptyUtils;
import com.alm.token.utils.LanguageUtils;
import com.alm.token.utils.LogUtil;
import com.alm.token.utils.SpUtil;
import com.alm.token.utils.Utils;
import com.alm.token.widget.CustomBanner;
import com.alm.token.widget.MyScrollView;
import com.alm.token.widget.MyTextView;
import com.alm.token.widget.WalletScrollViewPager;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.request.RequestOptions;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.web3j.crypto.CipherException;
import org.web3j.crypto.Keys;
import org.web3j.crypto.WalletFile;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import baibeiwallet.BaibeiWallet;
import baibeiwallet.ClipboardUtils;
import baibeiwallet.Constant;
import baibeiwallet.WalletDaoUtils;
import baibeiwallet.WalletManager;
import baibeiwallet.WalletManagerActivity1;
import baibeiwallet.activity.CreateWalletActivity1;
import baibeiwallet.activity.InprotWalletActivity1;
import baibeiwallet.event.RefreshMeEvent;
import baibeiwallet.event.RefreshPriceEvent;
import baibeiwallet.event.RefreshWalletEvent;
import baibeiwallet.event.SelWalletEvent;
import baibeiwallet.event.getUserWalletEvent;
import baibeiwallet.model.ETHWallet3;
import baibeiwallet.utils.BaiBeiWalletUtils;
import baibeiwallet.utils.DialogUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

public class WalletPageFrag extends BaseViewPageFragment implements UserWalletView<UserWalletData>,
        ViewPager.OnPageChangeListener, MainActivity.MainActyLisenter, RadioGroup.OnCheckedChangeListener {

    @BindView(R.id.convenientBanner)
    CustomBanner convenientBanner;
    @BindView(R.id.message)
    FrameLayout message;
    @BindView(R.id.fram_trawalletmore)
    FrameLayout framTraWalletMore;
    @BindView(R.id.fram_nodewalletmore)
    FrameLayout framNodeWalletMore;
    @BindView(R.id.tv_msgnumber)
    TextView tv_msgnumber;
    @BindView(R.id.view_pager)
    WalletScrollViewPager viewPager;
    @BindView(R.id.nestedscrollview)
    MyScrollView nestedScrollView;
    @BindView(R.id.tv_changelanguage)
    LinearLayout tvChangelanguage;
    @BindView(R.id.img_chinalanguage)
    ImageView img_chinalanguage;
    @BindView(R.id.tv_langrage)
    TextView tv_langrage;

    @BindView(R.id.tv_WalletName)
    MyTextView tvWalletName;
    @BindView(R.id.tv_candy)
    TextView tvCandy;

    @BindView(R.id.id_swipeRefreshLayout)
    SwipeRefreshLayout swipeRefreshLayout;
    @BindView(R.id.radioButton_trawallet_item)
    RadioButton radioButtonTrawalletItem;
    @BindView(R.id.radioButton_nodewallet_item)
    RadioButton radioButtonNodewalletItem;
    @BindView(R.id.rg_wallet_select)
    RadioGroup rgWalletSelect;
    Unbinder unbinder;

    private BannerPageAdapter bannerPageAdapter;
    public static UserWalletData.DataBean dataBean;
    private ChannelTypeData.DataBean channelTypeDataBean;

    private DrawIndexData.DataBean drawIndexDataBean;
    private boolean[] fragmentsUpdateFlag = {false, false};
    private List<Object> dataBeans = new ArrayList<>();
    UserWalletData.DataBean entity;
    BaibeiWallet entity1;
    private int walletType = 0;


    public static WalletPageFrag newInstance() {
        WalletPageFrag fragment = new WalletPageFrag();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected MyPreenter initPreenter() {
        return preenter = new MyPreenter(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.viewpage_fragment_wallet;
    }

    @Override
    protected void initVariables() {
        int flag = LanguageUtils.getSetIndex();
        img_chinalanguage.setImageDrawable(getResources().getDrawable(flag == 4 ? R.drawable.japanese : flag == 2 ? R.drawable.america
                : flag == 3 ? R.drawable.korea : R.drawable.china));
        tv_langrage.setText(flag == 4 ? "日本語" : flag == 2 ? "English"
                : flag == 3 ? "한국어" : "中文");
    }

    @Override
    protected void initViews(View view) {
        initBanner();
    }

    private void initBanner() {
        entity = new UserWalletData.DataBean();
        entity1 = new BaibeiWallet(new WalletFile(), null);
        entity.setTotalMoney("0");

        dataBeans.clear();
        dataBeans.add(entity);
        dataBeans.add(entity1);
        convenientBanner.setPages(new CBViewHolderCreator<BannerHolderView>() {
            @Override
            public BannerHolderView createHolder() {
                return new BannerHolderView();
            }
        }, dataBeans).setPageIndicator(new int[]{R.drawable.zsd_grey, R.drawable.zsd_light});
        convenientBanner.setOnPageChangeListener(this);
        convenientBanner.setManualPageable(false);
        bannerPageAdapter = new BannerPageAdapter(getChildFragmentManager());
        bannerPageAdapter.setDat(dataBean, fragmentsUpdateFlag);
        viewPager.setAdapter(bannerPageAdapter);
        viewPager.setClipChildren(false);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                swipeRefreshLayout.setRefreshing(false);

                if (walletType == 0) {
//                    showToast("刷新第一钱包" + "  walletType=" + walletType);
                    loadData();
                } else {
//                    showToast("刷新第二钱包" + "  walletType=" + walletType);
                    EventBus.getDefault().post(new RefreshWalletEvent(-1));
                }


            }
        });
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (convenientBanner.getCurrentItem() != position) {
                    convenientBanner.setcurrentitem(position);
                    walletType = position;
                    if (position == 1) {
                        String name = WalletDaoUtils.getCurrent() != null && !TextUtils.isEmpty(
                                WalletDaoUtils.getCurrent().getName()) ? WalletDaoUtils.getCurrent().getName() + " Wallet" : "Wallet";
                        tvWalletName.setText(name);
//                        tvChangelanguage.setVisibility(View.GONE);
                        message.setVisibility(View.GONE);
                        framTraWalletMore.setVisibility(View.GONE);
                        framNodeWalletMore.setVisibility(View.VISIBLE);
                    } else {
                        tvWalletName.setText(getString(R.string.app_name));
//                        tvChangelanguage.setVisibility(View.VISIBLE);
//                        tvChangelanguage.setVisibility(View.GONE);
//                        message.setVisibility(View.VISIBLE);
                        message.setVisibility(View.GONE);
                        framTraWalletMore.setVisibility(View.VISIBLE);
                        framNodeWalletMore.setVisibility(View.GONE);
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
//        showToast("position=" + position);
        LogUtil.e("040 getChildCount=" + convenientBanner.getViewPager().getChildCount());


        if (viewPager.getCurrentItem() != position) {
            viewPager.setCurrentItem(position);
            walletType = position;

            if (position == 1) {

                String name = WalletDaoUtils.getCurrent() != null && !TextUtils.isEmpty(
                        WalletDaoUtils.getCurrent().getName()) ? WalletDaoUtils.getCurrent().getName() + " Wallet" : "Wallet";
                tvWalletName.setText(name);
//                tvChangelanguage.setVisibility(View.GONE);
                message.setVisibility(View.GONE);
                framTraWalletMore.setVisibility(View.GONE);
                framNodeWalletMore.setVisibility(View.VISIBLE);

//                LogUtil.e("030 price=" + price);
//                DecimalFormat dec = new DecimalFormat("0.0000");
//                showToast( ((TextView) convenientBanner.getViewPager().getChildAt(position).findViewById(R.id.tv_totalMoney_qukuai))
//                        .getText().toString());
//                ((TextView) convenientBanner.getViewPager().getChildAt(position).findViewById(R.id.tv_totalMoney_qukuai))
//                        .setText("$ " + dec.format(price));


            } else {
                tvWalletName.setText(getString(R.string.app_name));
//                tvChangelanguage.setVisibility(View.VISIBLE);
//                tvChangelanguage.setVisibility(View.GONE);
                //                        message.setVisibility(View.VISIBLE);
                message.setVisibility(View.GONE);
                framTraWalletMore.setVisibility(View.VISIBLE);
                framNodeWalletMore.setVisibility(View.GONE);
            }
        }

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void mainActySetWallet(int walletType) {
        if (convenientBanner.getCurrentItem() != walletType) {
            convenientBanner.setcurrentitem(walletType);
            this.walletType = walletType;

            if (walletType == 1) {
                String name = WalletDaoUtils.getCurrent() != null && !TextUtils.isEmpty(
                        WalletDaoUtils.getCurrent().getName()) ? WalletDaoUtils.getCurrent().getName() + " Wallet" : "Wallet";
                tvWalletName.setText(name);
//                tvChangelanguage.setVisibility(View.GONE);
                message.setVisibility(View.GONE);
                framTraWalletMore.setVisibility(View.GONE);
                framNodeWalletMore.setVisibility(View.VISIBLE);
            } else {
                tvWalletName.setText(getString(R.string.app_name));
//                tvChangelanguage.setVisibility(View.VISIBLE);
//                tvChangelanguage.setVisibility(View.GONE);
                //                        message.setVisibility(View.VISIBLE);
                message.setVisibility(View.GONE);
                framTraWalletMore.setVisibility(View.VISIBLE);
                framNodeWalletMore.setVisibility(View.GONE);
            }
        }

//        convenientBanner.setcurrentitem(walletType);
//        this.walletType=walletType;
    }

    public double price = 0.0000d;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {

        switch (group.getCheckedRadioButtonId()) {
            case R.id.radioButton_trawallet_item:
                mainActySetWallet(0);
                break;
            case R.id.radioButton_nodewallet_item:
                if (WalletManager.getInstance().getWalletAll().size() == 0 || WalletDaoUtils.getCurrent() == null) {//没有钱包
//                    if(radioButtonNodewalletItem.isChecked()){
//                        radioButtonNodewalletItem.setChecked(false);
                    radioButtonTrawalletItem.setChecked(true);
//                    }
                    showCreatNodeDialog();
                    break;
                }
                mainActySetWallet(1);
                break;
        }
    }

    private class BannerHolderView implements Holder<Object> {
        TextView tvTotalshow;
        TextView tvTotalMoney;
        ImageView imgMore, imgChangeshow;
        TextView tvMore;
        TextView tvTotalGetYesterdayMoney;
        TextView tvTotalGetMoney;
        RelativeLayout lyBannerbgd;
        boolean canshown;
        //        private ImageView imageView;
        private RelativeLayout mrlyBannerView;
        RequestOptions myOptions;

        LinearLayout lyBannerbgdQukuaiwallet, lyBannerbgdLehuobao;
        TextView tvTotalMoneyQukuai, tvWalletAdressQukuai, tvMoreQukuai, tvWalletNameQukuai;
        ImageView imgAdressqrdQqukuai, imgMoreQukuai;

        public BannerHolderView() {
            myOptions = RequestOptions.bitmapTransform(new MultiTransformation(
                    new CenterCrop(),
                    new RoundedCornersTransformation(Utils.dp2px(getActivity(), 8), 0)));
        }

        @Override
        public View createView(Context context) {
            mrlyBannerView = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.activity_bannerview, null);
            lyBannerbgdLehuobao = mrlyBannerView.findViewById(R.id.ly_bannerbgd_lehuobao);
            tvTotalshow = mrlyBannerView.findViewById(R.id.tv_totalshow);
            tvTotalMoney = mrlyBannerView.findViewById(R.id.tv_totalMoney);
            imgMore = mrlyBannerView.findViewById(R.id.img_more);
            imgChangeshow = mrlyBannerView.findViewById(R.id.img_changeshow);
            tvMore = mrlyBannerView.findViewById(R.id.tv_more);
            tvTotalGetYesterdayMoney = mrlyBannerView.findViewById(R.id.tv_totalGetYesterdayMoney);
            tvTotalGetMoney = mrlyBannerView.findViewById(R.id.tv_totalGetMoney);
            lyBannerbgd = mrlyBannerView.findViewById(R.id.ly_bannerbgd);

            lyBannerbgdQukuaiwallet = mrlyBannerView.findViewById(R.id.ly_bannerbgd_qukuaiwallet);
            tvTotalMoneyQukuai = lyBannerbgdQukuaiwallet.findViewById(R.id.tv_totalMoney_qukuai);
            tvWalletAdressQukuai = lyBannerbgdQukuaiwallet.findViewById(R.id.tv_walletadress_qukuai);
            tvMoreQukuai = lyBannerbgdQukuaiwallet.findViewById(R.id.tv_more_qukuai);
            imgAdressqrdQqukuai = lyBannerbgdQukuaiwallet.findViewById(R.id.img_adressqrd_qukuai);
            imgMoreQukuai = lyBannerbgdQukuaiwallet.findViewById(R.id.img_more_qukuai);
            tvWalletNameQukuai = lyBannerbgdQukuaiwallet.findViewById(R.id.tv_qianbaoname);

            return mrlyBannerView;
//            imageView = new ImageView(context);
//            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
//            return imageView;
        }

        @Override
        public void UpdateUI(Context context, final int position, Object data1) {
            canshown = SpUtil.getBoolean(MyApp.context, ConStant.NEEDRESHOWN, true);
            imgChangeshow.setImageResource(canshown ? R.drawable.icon_isshowing : R.drawable.icon_isnotshow);

            imgChangeshow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //设置 是否显示或隐藏余额数字
                    canshown = SpUtil.getBoolean(MyApp.context, ConStant.NEEDRESHOWN, true);
                    imgChangeshow.setImageResource(!canshown ? R.drawable.icon_isshowing : R.drawable.icon_isnotshow);
                    SpUtil.putBoolean(MyApp.context, ConStant.NEEDRESHOWN, !canshown);
                    canshown = SpUtil.getBoolean(MyApp.context, ConStant.NEEDRESHOWN, true);
                    EventBus.getDefault().post(new getUserWalletEvent(dataBean));
                    tvTotalMoney.setText(canshown ? tvTotalMoney.getTag().toString() : "****");
                }
            });
//            GlideApp.with(getActivity())
//                    .load(R.drawable.banner_bg)
//                    .apply(myOptions)
//                    .into(imageView);

//            lyBannerbgd.setBackground(getResources().getDrawable(position % 2 == 1 ? R.drawable.banner_bg1 : R.drawable.banner_bg));

            if (data1 instanceof UserWalletData.DataBean) {
                UserWalletData.DataBean data = (UserWalletData.DataBean) data1;
                lyBannerbgdLehuobao.setVisibility(View.VISIBLE);
                lyBannerbgdQukuaiwallet.setVisibility(View.GONE);
                tvTotalMoney.setText("≈$ " + data.getTotalMoney());
                tvTotalMoney.setTag("≈$ " + data.getTotalMoney());
                tvTotalMoney.setText(canshown ? tvTotalMoney.getTag().toString() : "****");
                tvTotalGetYesterdayMoney.setText(getString(R.string.banner_hint_jinrijl, "" + data.getTotalGetYesterdayMoney()));
                tvTotalGetMoney.setText(getString(R.string.banner_hint_leijijl, "" + data.getTotalGetMoney()));
                imgMore.setBackground(getResources().getDrawable(position % 2 == 1 ? R.drawable.jilu_bg1 : R.drawable.jilu_bg));

                imgMore.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
//                        if (channelTypeDataBean != null) {
                        startActivity(BillActivity.class);
//                        }
                    }
                });
            } else if (data1 instanceof BaibeiWallet) {
                BaibeiWallet baibeiWallet = (BaibeiWallet) data1;
                lyBannerbgdLehuobao.setVisibility(View.GONE);
                lyBannerbgdQukuaiwallet.setVisibility(View.VISIBLE);
                tvTotalMoneyQukuai.setText("$ " + CommonUtil.saveToPoint2WithNo(price));
                tvTotalMoneyQukuai.setTag(99);
                LogUtil.e("999 99  99  price=" + price);
//                if (mBaibeiWallet != null && mBaibeiWallet.getWalletFile() != null && mBaibeiWallet.getMnemonic() != null) {

                if (mBaibeiWallet == null && WalletDaoUtils.getCurrent() != null) {
                    try {
                        mBaibeiWallet = BaiBeiWalletUtils.loadByKeyStore(WalletDaoUtils.getCurrent().getPassword(), WalletDaoUtils.getCurrent().getKeystorePath());
                        mBaibeiWallet.setPassword(WalletDaoUtils.getCurrent().getPassword());
                        mBaibeiWallet.setWalletName(WalletDaoUtils.getCurrent().getName());
                        EventBus.getDefault().post(new RefreshWalletEvent(-2));
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (CipherException e) {
                        e.printStackTrace();
                    }
                }

                if (WalletDaoUtils.getCurrent() == null) {
                    EventBus.getDefault().post(new RefreshWalletEvent(-2));
                }

//                else {
//                    EventBus.getDefault().post(new RefreshWalletEvent(-2));
//                }

                if (mBaibeiWallet != null && !TextUtils.isEmpty(mBaibeiWallet.getWalletFile().getAddress())) {
//                    if (WalletDaoUtils.getCurrent().getAddress().equalsIgnoreCase(Keys.toChecksumAddress(mBaibeiWallet.getWalletFile().getAddress()))) {
//                        showToast("钱包一样");
//                    }
//                    showToast("钱包一样");
                    baibeiWalletAdress = Keys.toChecksumAddress(mBaibeiWallet.getWalletFile().getAddress());

                } else {
                    baibeiWalletAdress = "";
                }
                if (!TextUtils.isEmpty(baibeiWalletAdress)) {
                    tvWalletAdressQukuai.setText(baibeiWalletAdress.length() >= 40 ? baibeiWalletAdress.substring(0, 9)
                            + "...." + baibeiWalletAdress.substring(baibeiWalletAdress.length() - 11, baibeiWalletAdress.length()) : baibeiWalletAdress);
//                    tvWalletNameQukuai.setText(mBaibeiWallet.getWalletName());
                } else {
                    tvWalletAdressQukuai.setText("------------");
//                    tvWalletNameQukuai.setText("钱包");
                }

                tvMoreQukuai.setText("ETH");
                imgMoreQukuai.setBackground(getResources().getDrawable(position % 2 == 1 ? R.drawable.jilu_bg1 : R.drawable.jilu_bg));
//                }
                imgMoreQukuai.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (WalletDaoUtils.getCurrent() == null) {
//                                preenter.getDrawIndexData("1");
                            showToast(getString(R.string.profile_hint_item5));
                            return;
                        }
//                        if (!TextUtils.isEmpty(MyApp.QuKuaiAdress)) {//记录
//                            showToast("记录");
//                        } else {//创建钱包
//                            showToast("创建钱包");
//                        }


//                        showToast("创建钱包");
//                        Intent i = new Intent(getActivity(), CreateWalletActivity1.class);
//                        startActivity(i);
                    }
                });
                tvWalletAdressQukuai.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (tvWalletAdressQukuai.getText().toString().indexOf("------------") == -1) {
                            ClipboardUtils.copy(tvWalletAdressQukuai.getText().toString());
                        }
                    }
                });
                imgAdressqrdQqukuai.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (WalletDaoUtils.getCurrent() == null) {
//                                preenter.getDrawIndexData("1");
                            showToast(getString(R.string.profile_hint_item5));
                            return;
                        }
                        Intent intent1 = new Intent(getActivity(), TransferQrCodeActivity_new.class);
//                        Intent intent1 = new Intent(getActivity(), TransferQrCodeActivity.class);
                        intent1.putExtra("jiedianwallet", true);
                        intent1.putExtra("bizhongType", 1);
                        startActivity(intent1);
                    }
                });

            }
//            if (position == 0) {
//                lyBannerbgdLehuobao.setVisibility(View.VISIBLE);
//                lyBannerbgdQukuaiwallet.setVisibility(View.GONE);
//                tvTotalMoney.setText("≈$ " + data.getTotalMoney());
//                tvTotalGetYesterdayMoney.setText("今日激励+" + data.getTotalGetYesterdayMoney());
//                tvTotalGetMoney.setText("累计激励+" + data.getTotalGetMoney());
//                imgMore.setBackground(getResources().getDrawable(position % 2 == 1 ? R.drawable.jilu_bg1 : R.drawable.jilu_bg));
//
//                imgMore.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
////                    showToast("position=" + position);
//                        if (channelTypeDataBean != null) {
//                            startActivity(BillActivity.class);
//                        }
//                    }
//                });
//            } else {
//                lyBannerbgdLehuobao.setVisibility(View.GONE);
//                lyBannerbgdQukuaiwallet.setVisibility(View.VISIBLE);
////                if (!TextUtils.isEmpty(MyApp.QuKuaiAdress)) {
////
////                    tvTotalMoneyQukuai.setText("$5000.00");
////                    if (MyApp.QuKuaiAdress.length() >= 40) {
////                        tvWalletAdressQukuai.setText(MyApp.QuKuaiAdress.substring(0, 9) + "...."
////                                + MyApp.QuKuaiAdress.substring(MyApp.QuKuaiAdress.length() - 11, MyApp.QuKuaiAdress.length()));
////                    } else {
////                        tvWalletAdressQukuai.setText(MyApp.QuKuaiAdress);
////
////                    }
////                    tvMoreQukuai.setText("记录");
////                    imgMoreQukuai.setBackground(getResources().getDrawable(position % 2 == 1 ? R.drawable.jilu_bg1 : R.drawable.jilu_bg));
////                } else {
//                tvTotalMoneyQukuai.setText("$0.00");
//                tvWalletAdressQukuai.setText("------------");
//                tvMoreQukuai.setText("创建钱包");
//                imgMoreQukuai.setBackground(getResources().getDrawable(position % 2 == 1 ? R.drawable.jilu_bg1 : R.drawable.jilu_bg));
////                }
//                imgMoreQukuai.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
////                        if (!TextUtils.isEmpty(MyApp.QuKuaiAdress)) {//记录
////                            showToast("记录");
////                        } else {//创建钱包
////                            showToast("创建钱包");
////                        }
//                        showToast("创建钱包");
//
//                        Intent i = new Intent(getActivity(), CreateWalletActivity1.class);
//                        startActivity(i);
//                    }
//                });
//                imgAdressqrdQqukuai.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
////                        if (!TextUtils.isEmpty(MyApp.QuKuaiAdress)) {//记录
////                            showToast("记录");
////                        } else {//创建钱包
////                            showToast("创建钱包");
////                        }
//                        showToast("地址充值");
//
//                    }
//                });
//
//            }


        }
    }

    @Override
    protected void loadData() {
//        preenter.getUserPayAdress();
        preenter.getUserWalletData();
        preenter.getChannelTypeData();
//        preenter.getDrawIndexData("");
    }

    @Override
    public void onResume() {
        super.onResume();

    }

    @Override
    public void onStart() {
        super.onStart();
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    BaibeiWallet mBaibeiWallet;
    int mIndex = -1;
    String baibeiWalletAdress = "";
    List<ETHWallet3> ethWallets = new ArrayList<>();
    List<BaibeiWallet> baibeiWallets = new ArrayList<>();

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onSelWalletEvent(SelWalletEvent sel) {
        price = sel.price;
        if (sel.index >= 0) {
            mBaibeiWallet = WalletManager.getInstance().getWallet(sel.index);
            mIndex = sel.index;
        }
//        mBaibeiWallet = WalletManager.getInstance().getWallet(sel.index);
//        mIndex = sel.index;

        ethWallets = WalletDaoUtils.loadAll();
        dataBeans.clear();
        if (ethWallets != null && ethWallets.size() != 0 && mBaibeiWallet != null) {
            for (ETHWallet3 ethWallet : ethWallets) {
                if (ethWallet.getAddress().equalsIgnoreCase(Keys.toChecksumAddress(mBaibeiWallet.getWalletFile().getAddress()))) {
//                    showToast("更新选择的钱包");
                    WalletDaoUtils.updateCurrent(ethWallet.getId());
                    EventBus.getDefault().post(new RefreshWalletEvent(mIndex));
                    break;
                }
            }
            dataBeans.add(0, dataBean);
            dataBeans.add(mBaibeiWallet);


        } else {
            mBaibeiWallet = null;
            dataBeans.add(0, dataBean);
            dataBeans.add(new BaibeiWallet(new WalletFile(), null));
        }
//
//
//        baibeiWallets = WalletManager.getInstance().getWalletAll();
//        if (ethWallets != null && baibeiWallets != null && ethWallets.size() > mIndex && baibeiWallets.size() > mIndex) {
//            if (baibeiWallets.get(mIndex).getMnemonic().equalsIgnoreCase(ethWallets.get(mIndex).getMnemonic())) {//选择了一样的
//                WalletDaoUtils.updateCurrent(ethWallets.get(mIndex).getId());
//            }
//        }


//            UserWalletData.DataBean entity1 = new UserWalletData.DataBean();

//        dataBeans.add(0, dataBean);
//        dataBeans.add(mBaibeiWallet);
//            dataBeans.add(entity1);

        convenientBanner.setPages(new CBViewHolderCreator<BannerHolderView>() {
            @Override
            public BannerHolderView createHolder() {
                return new BannerHolderView();
            }
        }, dataBeans).setPageIndicator(new int[]{R.drawable.zsd_grey, R.drawable.zsd_light});
        convenientBanner.setOnPageChangeListener(this);
        convenientBanner.setManualPageable(false);
        if (!sel.isiInit) {
            if (convenientBanner.getCurrentItem() != 1) {
                convenientBanner.setcurrentitem(1);
                this.walletType = 1;

                if (walletType == 1) {
                    String name = WalletDaoUtils.getCurrent() != null && !TextUtils.isEmpty(
                            WalletDaoUtils.getCurrent().getName()) ? WalletDaoUtils.getCurrent().getName() + " Wallet" : "Wallet";
                    tvWalletName.setText(name);
//                    tvChangelanguage.setVisibility(View.GONE);
                    message.setVisibility(View.GONE);
                    framTraWalletMore.setVisibility(View.GONE);
                    framNodeWalletMore.setVisibility(View.VISIBLE);
                } else {
                    tvWalletName.setText(getString(R.string.app_name));
//                    tvChangelanguage.setVisibility(View.VISIBLE);
//                    tvChangelanguage.setVisibility(View.GONE);
                    //                        message.setVisibility(View.VISIBLE);
                    message.setVisibility(View.GONE);
                    framTraWalletMore.setVisibility(View.VISIBLE);
                    framNodeWalletMore.setVisibility(View.GONE);
                }
            }
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onUserWalletEvent1(getUserWalletEvent userWalletEvent) {
        if (userWalletEvent.dataBean == null) {
            loadData();
        }
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onRefreshPriceEvent(RefreshPriceEvent sel) {
        price = sel.price;
        LogUtil.e("010 price=" + price);
//        convenientBanner.setPages(new CBViewHolderCreator<BannerHolderView>() {
//            @Override
//            public BannerHolderView createHolder() {
//                return new BannerHolderView();
//            }
//        }, dataBeans).setPageIndicator(new int[]{R.drawable.zsd_grey, R.drawable.zsd_light});
//        convenientBanner.setOnPageChangeListener(this);
//        LogUtil.e("011 walletType=" + walletType);
//
//        if(!tvWalletName.getText().toString().equalsIgnoreCase("ioToken")){
//            convenientBanner.setcurrentitem(1);
//        }

//        showToast(((TextView) convenientBanner.getViewPager().getChildAt(1).findViewById(R.id.tv_totalMoney_qukuai))
//                .getText().toString());
//        LogUtil.e("040 getChildCount=" + convenientBanner.getViewPager().getChildCount());
        for (int i = 0; i < convenientBanner.getViewPager().getChildCount(); i++) {
            ((TextView) convenientBanner.getViewPager().getChildAt(i).findViewById(R.id.tv_totalMoney_qukuai)).setText("$ " + CommonUtil.saveToPoint2WithNo(price));
//            LogUtil.e("060 --" + ((TextView) convenientBanner.getViewPager().getChildAt(i).findViewById(R.id.tv_totalMoney_qukuai))
//                    .getText().toString());
        }


//        ((TextView) convenientBanner.getViewPager().getChildAt(1).findViewById(R.id.tv_totalMoney_qukuai))
//                .setText("$ " + dec.format(price));


//        entity1.setMoney(price);
//        dataBeans.remove(1);
//        dataBeans.add(1, entity1);
//        convenientBanner.no();


//        if (!sel.isiInit) {
//            if (convenientBanner.getCurrentItem() != 1) {
//                convenientBanner.setcurrentitem(1);
//                this.walletType = 1;
//                if (walletType == 1) {
//                    String name = WalletDaoUtils.getCurrent() != null && !TextUtils.isEmpty(
//                            WalletDaoUtils.getCurrent().getName()) ? WalletDaoUtils.getCurrent().getName() + " Wallet" : "Wallet";
//                    tvWalletName.setText(name);
//                    tvChangelanguage.setVisibility(View.GONE);
//                    message.setVisibility(View.GONE);
//                    framWalletMore.setVisibility(View.VISIBLE);
//                } else {
//                    tvWalletName.setText("ioToken");
//                    tvChangelanguage.setVisibility(View.VISIBLE);
//                    message.setVisibility(View.VISIBLE);
//                    framWalletMore.setVisibility(View.GONE);
//                }
//            }
//        }
    }

    UserWalletData.DataBean.SysMsgBean sysMsgBean;
    UserWalletData.DataBean.UserMsgBean userMsgBean;

    @Override
    public void jumpToLoginAct(int staue) {
        if (staue == 3) {
//            showToast(getString(R.string.common_relogin));
//            Intent intent = new Intent();
//            intent.setAction(ConStant.EXIT_APP);
//            getActivity().sendBroadcast(intent);
//            startActivity(BlockWalletLoginActivity.class);
//            getActivity().finish();
        } else if (staue == 4) {
//            showToast(getString(R.string.paypasw_hint_setpaypsw));
//            Intent intent = new Intent(getActivity(),PayPwdActivity.class);
//            intent.putExtra("PayPwdActivityType",PayPwdActivity.PAYPSW_SET);
//            startActivity(intent);
//            getActivity().finish();
            showToSetPaypswDialog();
        } else if (staue == 666) {
            showToUpdata();
        }
    }

    @Override
    public void getData(UserWalletData userWalletData) {
        if (EmptyUtils.isEmpty(rgWalletSelect.getTag())) {
            rgWalletSelect.setTag(1);
            rgWalletSelect.setOnCheckedChangeListener(this);
        }
        if (userWalletData.getStatus() == 0) {
//            showToast("首页数据请求成功");
            dataBean = userWalletData.getData();

            EventBus.getDefault().post(new getUserWalletEvent(dataBean));

//            fragmentsUpdateFlag[0] = true;
//            bannerPageAdapter.setDat(dataBean, fragmentsUpdateFlag);
//            bannerPageAdapter.notifyDataSetChanged();

            dataBeans.clear();
            dataBeans.add(0, dataBean);
            dataBeans.add(entity1);
//            dataBeans.add(entity1);

            convenientBanner.setPages(new CBViewHolderCreator<BannerHolderView>() {
                @Override
                public BannerHolderView createHolder() {
                    return new BannerHolderView();
                }
            }, dataBeans).setPageIndicator(new int[]{R.drawable.zsd_grey, R.drawable.zsd_light});
            convenientBanner.setOnPageChangeListener(this);
            convenientBanner.setManualPageable(false);
//            List<UserWalletData.DataBean.UserMsgBean> userMsg = new ArrayList<>();
//            UserWalletData.DataBean.UserMsgBean us1 = new UserWalletData.DataBean.UserMsgBean();
//            us1.setId(3);
//            us1.setTitle("糖果");
//            us1.setContent("恭喜获得zuoqi168派发0.4306糖果");
//            us1.setTitle("Candy");
//            us1.setContent("sdsdsd zuoqi168 sd 0.4306 candy!");
//            userMsg.add(us1);
//            dataBean.setUserMsg(userMsg);

            if (dataBean.getUserMsg() != null && dataBean.getUserMsg().size() != 0) {
                userMsgBean = dataBean.getUserMsg().get(dataBean.getUserMsg().size() - 1);
                if (SpUtil.getInt(MyApp.context, ConStant.USERMSGID, 0) != userMsgBean.getId()) {//需要弹框显示
                    SpUtil.putInt(MyApp.context, ConStant.USERMSGID, userMsgBean.getId());
                    showCodeDialog();
//                    DialogUtils.showUserMsgInfor(getActivity(), userMsgBean, (pwd) -> {
//                        startActivity(BillActivity.class);
//                    });
                }
            }

            if (dataBean.getSysMsg() != null && dataBean.getSysMsg().size() != 0) {
                sysMsgBean = dataBean.getSysMsg().get(dataBean.getSysMsg().size() - 1);
                for (int i = dataBean.getSysMsg().size() - 1; i >= 0; i--) {
                    if (dataBean.getSysMsg().get(i).getNeedUp() == 1) {
                        sysMsgBean = dataBean.getSysMsg().get(i);
                        break;
                    }
                }
                if (sysMsgBean.getNeedUp() == 1 &&
                        (MyApp.canTanchuang || SpUtil.getInt(MyApp.context, ConStant.SYSMSGID, 0) != sysMsgBean.getId()) &&
                        sysMsgBean.getUpEndTime() >= new Date().getTime() && sysMsgBean.getUpStartTime() <= new Date().getTime()) {//需要弹框显示
                    SpUtil.putInt(MyApp.context, ConStant.SYSMSGID, sysMsgBean.getId());
                    DialogUtils.showInfor(getActivity(), sysMsgBean, (pwd) -> {
                        MyApp.canTanchuang = false;
                        Intent intent1 = new Intent(getContext(), MessageDetailActivity.class);
                        intent1.putExtra("intentType", 1);
                        intent1.putExtra("sysMsgBean", sysMsgBean);
                        startActivity(intent1);
                    });
                }
            }

            List<UserWalletData.DataBean.WalletsBean> wallets = dataBean.getWallets();
            if (wallets != null && wallets.size() != 0) {
                for (UserWalletData.DataBean.WalletsBean walletsBean : wallets) {
                    preenter.getCoinDetailData(walletsBean.getId() + "");
                }
            }

        }
    }

    /***  弹出提示公告  ***/
    private void showCodeDialog() {
        CandyDialogFragment dialogFragment = new CandyDialogFragment();
        dialogFragment.setDialogBean(new BaseDialogBean(userMsgBean));

        dialogFragment.setListener(new CandyDialogFragment.ClickListener() {
            @Override
            public void Listener(String name, int potion) {
                startActivity(BillActivity.class);
            }
        });

        dialogFragment.show(getChildFragmentManager(), "NoticeDialogFragment");
        getFragmentManager().executePendingTransactions();
    }

    /***  弹出提示公告  ***/
    private void showCreatNodeDialog() {
        CreatNodeDialogFragment dialogFragment = new CreatNodeDialogFragment();
        UserWalletData.DataBean.UserMsgBean userMsgBean1 = new UserWalletData.DataBean.UserMsgBean();
        userMsgBean1.setTitle(getString(R.string.common_warmprompt));
        userMsgBean1.setEnTitle(getString(R.string.common_warmprompt));
        userMsgBean1.setContent(getString(R.string.wallet_hint_nowallet_worm));
        userMsgBean1.setEnContent(getString(R.string.wallet_hint_nowallet_worm));
        dialogFragment.setDialogBean(new BaseDialogBean(userMsgBean1));

        dialogFragment.setListener(new CreatNodeDialogFragment.ClickListener() {
            @Override
            public void Listener(String name, int potion) {
                if (potion == 2) {
                    Intent i = new Intent(getActivity(), WalletManagerActivity1.class);
                    startActivity(i);

                } else {
                    //                    Intent i1 = new Intent(getActivity(), InprotWalletActivity1.class);
//                    startActivity(i1);
                }

            }
        });
        dialogFragment.show(getFragmentManager(), "NoticeDialogFragment");
        getFragmentManager().executePendingTransactions();
    }

    @Override
    public void getChannelTypeData(ChannelTypeData channelTypeData) {
        if (channelTypeData.getStatus() == 0) {
            channelTypeDataBean = channelTypeData.getData();
            MyApp.setChannelTypeDataBean(channelTypeDataBean);
        }
    }

    @Override
    public void getDrawIndexData(DrawIndexData drawIndexData) {
//        if (drawIndexData.getStatus() == 0) {
//            drawIndexDataBean = drawIndexData.getData();
//            MyApp.setDrawIndexDataBean(drawIndexDataBean);
//        }
    }

    @Override
    public void getUserPayAdress(UserPayAdressData userPayAdressData) {
//        if (userPayAdressData.getStatus() == 0) {
//            if (userPayAdressData.getData() != null && userPayAdressData.getData().size() != 0) {
//                Map<String, String> bizhongAdressMap = new HashMap<>();
//                for (Map<String, String> map : userPayAdressData.getData()) {
//
//                    if (map != null) {
//                        bizhongAdressMap.putAll(map);
//                    }
//                }
//                MyApp.bizhongAdressMap = bizhongAdressMap;
//            }
//        }
    }

    @Override
    public void getCoinDetailData(CoinDetailData coinDetailData) {
        if (coinDetailData.getStatus() == 0 && coinDetailData.getData() != null) {
            MyApp.coinDetailDataBean.add(coinDetailData.getData());
            if (!TextUtils.isEmpty(coinDetailData.getData().getContract())) {
                Constant.G12ContractAddress = coinDetailData.getData().getContract();
                Constant.G12ContractName = coinDetailData.getData().getWallet().getName();
                Constant.G12ContractPrice = coinDetailData.getData().getWallet().getPrice();
                Constant.G12ContractLogo = coinDetailData.getData().getWallet().getLogo();
                EventBus.getDefault().post(new RefreshWalletEvent(-1));
            }
            LogUtil.e("CoinDetailData=" + coinDetailData.getData().getContract());
        }
    }

    @Override
    public void onError(String error) {

    }

    @Override
    public void ShowProgress() {

        showWaitDialog();
    }

    @Override
    public void hideProgress() {
        hideWaitDialog();

    }

    @Override
    public void onClick(View v) {
    }

    @OnClick({R.id.message, R.id.tv_changelanguage, R.id.fram_trawalletmore, R.id.fram_nodewalletmore, R.id.tv_candy})
    public void onViewClicked(View view) {
        switch (view.getId()) {

            case R.id.message:
                startActivity(MessageActivity.class);
                break;
            case R.id.tv_changelanguage:
                startActivity(SetLanguageActivity.class);
                break;
            case R.id.fram_nodewalletmore:
                showPopupMenu2(framNodeWalletMore);

                break;
            case R.id.fram_trawalletmore:
                showPopupMenu3(framTraWalletMore);
                break;
            case R.id.tv_candy:

                startActivity(CandyActivity.class);

                break;

        }
    }

    public void showPopupMenu2(View view) {
        //参数View 是设置当前菜单显示的相对于View组件位置，具体位置系统会处理
        PopupMenu popupMenu = new PopupMenu(getActivity(), view);
        //加载menu布局
        popupMenu.getMenuInflater().inflate(R.menu.menu_popmenu_nodewalletmore, popupMenu.getMenu());

//        if (WalletManager.getInstance().getWalletAll().size() == 0 || WalletDaoUtils.getCurrent() == null) {//没有钱包
//            popupMenu.getMenu().findItem(R.id.addtoken).setVisible(false);
//            popupMenu.getMenu().findItem(R.id.walletmanger).setVisible(false);
//        }
//        else {//有钱包
//            popupMenu.getMenu().findItem(R.id.creatwallet).setVisible(false);
//            popupMenu.getMenu().findItem(R.id.inportwallet).setVisible(false);
//        }
        //设置menu中的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (EmptyUtils.isEmpty(bannerPageAdapter) || EmptyUtils.isEmpty(bannerPageAdapter.getItem(1))) {
                    showToast(getString(R.string.common_waitritry));
                    return true;
                }
                switch (item.getItemId()) {
                    case R.id.addtoken:
                        showToast(getString(R.string.main_hint_warn1));
                        break;

                    case R.id.walletmanger:
                        if (EmptyUtils.isNotEmpty(bannerPageAdapter.getItem(1))) {
                            View view1 = new View(getActivity());
                            view1.setId(R.id.tab4);
                            ((BannerTwoFragment) bannerPageAdapter.getItem(1)).onTab(view1);
                        }

//                        startActivity(WalletManagerActivity1.class);
                        break;
                    case R.id.creatwallet:
//                        if (EmptyUtils.isNotEmpty(bannerPageAdapter.getItem(1))) {
//                            View view1 = new View(getActivity());
//                            view1.setId(R.id.tab4);
//                            ((BannerTwoFragment) bannerPageAdapter.getItem(1)).onTab(view1);
//                        }
                        Intent i = new Intent(getActivity(), CreateWalletActivity1.class);
                        startActivity(i);
                        break;
                    case R.id.inportwallet:
                        Intent i1 = new Intent(getActivity(), InprotWalletActivity1.class);
                        startActivity(i1);
                        break;


                    case R.id.sacnqr:
                        if (EmptyUtils.isNotEmpty(bannerPageAdapter.getItem(1))) {
                            View view1 = new View(getActivity());
                            view1.setId(R.id.tab1);
                            ((BannerTwoFragment) bannerPageAdapter.getItem(1)).onTab(view1);
                        }

//                        startActivity(WalletManagerActivity1.class);
                        break;
                    case R.id.recharge:
                        if (EmptyUtils.isNotEmpty(bannerPageAdapter.getItem(1))) {
                            View view1 = new View(getActivity());
                            view1.setId(R.id.tab3);
                            ((BannerTwoFragment) bannerPageAdapter.getItem(1)).onTab(view1);
                        }

//                        startActivity(WalletManagerActivity1.class);
                        break;
                    case R.id.extract:
                        if (EmptyUtils.isNotEmpty(bannerPageAdapter.getItem(1))) {
                            View view1 = new View(getActivity());
                            view1.setId(R.id.tab2);
                            ((BannerTwoFragment) bannerPageAdapter.getItem(1)).onTab(view1);
                        }

//                        startActivity(WalletManagerActivity1.class);
                        break;
                    case R.id.message:
                        onViewClicked(message);
                        break;
                }
                return true;
            }
        });
        popupMenu.show();
    }

    public void showPopupMenu3(View view) {
        //参数View 是设置当前菜单显示的相对于View组件位置，具体位置系统会处理
        PopupMenu popupMenu = new PopupMenu(getActivity(), view);
        //加载menu布局
        popupMenu.getMenuInflater().inflate(R.menu.menu_popmenu_trawalletmore, popupMenu.getMenu());

//        if (WalletManager.getInstance().getWalletAll().size() == 0 || WalletDaoUtils.getCurrent() == null) {//没有钱包
//            popupMenu.getMenu().findItem(R.id.addtoken).setVisible(false);
//            popupMenu.getMenu().findItem(R.id.walletmanger).setVisible(false);
//        } else {//有钱包
//            popupMenu.getMenu().findItem(R.id.creatwallet).setVisible(false);
//            popupMenu.getMenu().findItem(R.id.inportwallet).setVisible(false);
//        }
        //设置menu中的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (EmptyUtils.isEmpty(bannerPageAdapter) || EmptyUtils.isEmpty(bannerPageAdapter.getItem(0))) {
                    showToast(getString(R.string.common_waitritry));
                    return true;
                }
                switch (item.getItemId()) {
                    case R.id.shoufukuanqd:
//                        if (EmptyUtils.isNotEmpty(bannerPageAdapter.getItem(0))) {
//                            View view1 = new View(getActivity());
//                            view1.setId(R.id.tab4);
//                            ((BannerOneFragment) bannerPageAdapter.getItem(0)).onTab(view1);
//                        }
                        if (EmptyUtils.isEmpty(MyApp.getUserData()) || EmptyUtils.isEmpty(MyApp.getUserData().getData()) || EmptyUtils.isEmpty(MyApp.getUserData().getData().getUser())) {
                            EventBus.getDefault().post(new RefreshMeEvent(1));
                            showToast(getString(R.string.common_loading));
                            break;
                        }
                        startActivity(TurnOutBiTB_ShoukuanActivity.class);
                        break;

                    case R.id.sacnqr:
                        if (EmptyUtils.isNotEmpty(bannerPageAdapter.getItem(0))) {
                            View view1 = new View(getActivity());
                            view1.setId(R.id.tab1);
                            ((BannerOneFragment) bannerPageAdapter.getItem(0)).onTab(view1);
                        }
                        break;
                    case R.id.recharge:
                        if (EmptyUtils.isNotEmpty(bannerPageAdapter.getItem(0))) {
                            View view1 = new View(getActivity());
                            view1.setId(R.id.tab3);
                            ((BannerOneFragment) bannerPageAdapter.getItem(0)).onTab(view1);
                        }
                        break;
                    case R.id.extract:
                        if (EmptyUtils.isNotEmpty(bannerPageAdapter.getItem(0))) {
                            View view1 = new View(getActivity());
                            view1.setId(R.id.tab2);
                            ((BannerOneFragment) bannerPageAdapter.getItem(0)).onTab(view1);
                        }
                        break;
                    case R.id.message:
                        onViewClicked(message);
                        break;

                    case R.id.currencyconversion:
                        startActivity(TransformActivity.class);
                        break;
                    case R.id.mpay:
                        startActivity(TurnOutBiTBActivity.class);
                        break;
                    case R.id.supegg:
                        startActivity(SuperColorEggActivity.class);
                        break;
                    case R.id.activity:
                        startActivity(ActivityListActivity.class);
                        break;
                }
                return true;
            }
        });
        popupMenu.show();
    }

    public class BannerPageAdapter extends FragmentPagerAdapter {

        // 		recyclerView.setNestedScrollingEnabled(false);
        List<Fragment> guides;
        UserWalletData.DataBean dataBean;
        boolean[] fragmentsUpdateFlag = {false, false};
        FragmentManager fm;

        public BannerPageAdapter(FragmentManager fm) {
            super(fm);
            this.fm = fm;
            guides = new ArrayList<>();
            guides.add(BannerOneFragment.newInstance(dataBean));
            guides.add(BannerTwoFragment.newInstance(null));
        }

        @Override
        public Fragment getItem(int position) {
            return guides.get(position);
        }

        @Override
        public int getItemPosition(Object object) {
            return POSITION_NONE;
        }

        @Override
        public int getCount() {
            return guides.size();
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            //得到缓存的fragment
            Fragment fragment = (Fragment) super.instantiateItem(container, position);
            //得到tag ❶
            String fragmentTag = fragment.getTag();
            if (fragmentsUpdateFlag[position]) {
                //如果这个fragment需要更新
                FragmentTransaction ft = fm.beginTransaction();
                //移除旧的fragment
                ft.remove(fragment);
                //换成新的fragment
                fragment = guides.get(position);
                //添加新fragment时必须用前面获得的tag ❶
                ft.add(container.getId(), fragment, fragmentTag);
                ft.attach(fragment);
                ft.commit();
                //复位更新标志
                fragmentsUpdateFlag[position] = false;
            }
            return fragment;
        }

        public void setDat(UserWalletData.DataBean dataBean, boolean[] fragmentsUpdateFlag) {
            this.dataBean = dataBean;
            this.fragmentsUpdateFlag = fragmentsUpdateFlag;
            guides.clear();
            guides.add(BannerOneFragment.newInstance(dataBean));
            guides.add(BannerTwoFragment.newInstance(null));
        }
    }


}
